$(function() {
	initEditForm();
	// 初始化Validate Form
	initValidateForm("edit-form");
});

/**
 * 初始化表单
 * @returns
 */
function initEditForm() {
	var key = $.common.getParam("key");
	if (!$.common.isEmpty(key)) {
		$.operate.get(gateway + app_admin + "/${objName}/get", {
			key : $.common.getParam("key")
		}, function(r) {
			var ${objName} = r.extends.${objName};
			<#list pk as id>
			// ${id.comments}
			$("#${id.attrname}").val(${objName}.${id.attrname});
			</#list>
			<#list columns as k>
			// ${k.comments}
			$("#${k.attrname}").val(${objName}.${k.attrname});
			</#list>
		});
	}
}

// validation规则
$("#edit-form").validate({
	rules: {
		<#list columns as k>
		${k.attrname}: {
		
		},
		</#list>
	},
	messages: {
		<#list columns as k>
		${k.attrname}: "",
		</#list>
	},
	submitHandler:function(){
		var formJson = $.common.formToJson("edit-form");
		$.operate.post(gateway + app_admin + '/${objName}/save', formJson, function(result) {
			if($.modal.tip(result)){
				$.modal.close();
			}
		});
	}
});